# Appendix R
# Santiago Lopez-Cariboni, 2022. "Political Regimes and Informal Social Insurance", Comparative Political Studies.


# ---- wd ----
wd <- 'replication_materials' 
setwd(wd)

# ---- packages ----
pkgs <- c("data.table", "foreign", 'panelView', 'fect', "lubridate", 
    "ggplot2", "dplyr", "mFilter", "texreg", "AER", "xts", "interflex", "gridExtra")
suppressPackageStartupMessages(sapply(pkgs,require,character.only=T))
# Plot the effects (use Johannes Karreth's function: https://github.com/jkarreth/JKmisc/blob/master/ggintfun.R)
# devtools::source_url("https://raw.githubusercontent.com/jkarreth/JKmisc/master/ggintfun.R")
source('code/functions/ggintfun.R')
# Function for time Lags
source('code/functions/lagpanel.R')


# ---- data ----
dt <- fread('data/dt_replication.csv')
dt <- dt[LDC==1, ]


# ---- Table 14  ----

library(stargazer)

dt.stats  <- dt[, .(year, 
TDLosses = tdlosses, 
TDLosses_cycle = outgap.tdl, 
GDP_Output_Gap  = l.outgap.gdp.hamilton,
Democracy_BMR = democracy,
Imports_GDP = imports,
Exports_GDP = exports,
Population_log = log(pop),
GDPpc_log = log(gdp.pcap),
Electricity_cosumption = elec.cons.pc,
Population_density = pop.density,
Regional_democracy = l.wreg.democracy,
Spatial_lag_GDPOutput_Gap = l.w.outgap.gdp.hamilton)]
stargazer(dt.stats)